<?php

/**
 * This is the model class for table "supplier".
 *
 * The followings are the available columns in table 'supplier':
 * @property integer $supplier_id
 * @property string $supplier_name
 * @property string $phone
 * @property string $email
 * @property string $fax
 * @property string $address
 * @property string $comment
 * @property string $contact_person_name
 * @property string $contact_person_phone
 * @property string $contact_person_email
 * @property string $contact_person_comment
 */
class Supplier extends SupplierBase
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Supplier the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'supplier';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('supplier_name, phone, email', 'required'),
			array('supplier_name, email, contact_person_name, contact_person_email', 'length', 'max'=>50),
			array('phone, fax, contact_person_phone', 'length', 'max'=>15),
			array('address', 'length', 'max'=>255),
			array('comment, contact_person_comment', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('supplier_id, supplier_name, phone, email, fax, address, comment, contact_person_name, contact_person_phone, contact_person_email, contact_person_comment', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'supplier_id' => 'Supplier',
			'supplier_name' => 'Supplier Name',
			'phone' => 'Phone',
			'email' => 'Email',
			'fax' => 'Fax',
			'address' => 'Address',
			'comment' => 'Comment',
			'contact_person_name' => 'Contact Person Name',
			'contact_person_phone' => 'Contact Person Phone',
			'contact_person_email' => 'Contact Person Email',
			'contact_person_comment' => 'Contact Person Comment',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('supplier_id',$this->supplier_id);
		$criteria->compare('supplier_name',$this->supplier_name,true);
		$criteria->compare('phone',$this->phone,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('fax',$this->fax,true);
		$criteria->compare('address',$this->address,true);
		$criteria->compare('comment',$this->comment,true);
		$criteria->compare('contact_person_name',$this->contact_person_name,true);
		$criteria->compare('contact_person_phone',$this->contact_person_phone,true);
		$criteria->compare('contact_person_email',$this->contact_person_email,true);
		$criteria->compare('contact_person_comment',$this->contact_person_comment,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}